package com.cg.controller;

import com.cg.dto.LoginDTO;
import com.cg.result.R;
import com.cg.service.AccountService;
import com.cg.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@CrossOrigin
@RestController
@Api(value = "login",description = "欢迎登录",tags="登录管理")
@RequestMapping("/api")
public class LoginController {
    @Autowired
    private AccountService accountService;
    @Autowired
    private IUserService userService;
    @PostMapping("/login")
    @ApiOperation("登录")
    public R login(@Validated @RequestBody LoginDTO loginDTO) {
            return accountService.login(loginDTO);
    }

    @PostMapping("/logout")
    @ApiOperation("登出")
    public R logout(){
        return accountService.logout();
    }

    @GetMapping ("/getCurrentUser")
    @ApiOperation("获取当前用户信息")
    public R<?> getCurrentUser(){
        return accountService.getCurrentUser();
    }

    @GetMapping("/getCurrentUserId")
    @ApiOperation("获取当前用户ID信息")
    public Long getCurrentUserId(){
        return accountService.getCurrentUserId();
    }
}
